<?php
/**
 * Created by YuanPan.
 * User: YuanPan
 * Date: 2018/5/12
 * Time: 19:02
 */

namespace app\api\controller\v2;


use app\api\lib\exception\MissException;
use app\api\lib\exception\SuccessMessage;
use app\api\service\TokenService;
use app\api\service\UserToken;

class TokenController extends BaseController
{
    //客户端发送code，获取token
    public function getToken($code='')
    {
        if(empty($code)) throw new MissException(['msg'=>'参数code必须存在']);
        $token = (new UserToken($code))->get();
        throw new SuccessMessage([
            'data' => $token,
        ]);
    }

    //验证token是否存在
    public function verifyToken($token = '')
    {
        if(!$token){
            throw new MissException(['msg' => 'token不允许为空']);
        }
        TokenService::verifyToken($token);
    }
}